{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-04-19T08:42:52.820233500Z",
     "start_time": "2024-04-19T08:42:50.289673Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn import datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[ True False  True]\n",
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n"
     ]
    },
    {
     "data": {
      "text/plain": "array([1, 9])"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x=np.arange(0,12).reshape(3,4)\n",
    "y=np.array([True,False,True])\n",
    "print(y)\n",
    "print(x)\n",
    "x[y,1]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:45:12.560187900Z",
     "start_time": "2024-04-19T08:45:11.617720900Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(50000, 2)\n",
      "(50000,)\n",
      "[0 1]\n"
     ]
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXwAAAD4CAYAAADvsV2wAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAA7/0lEQVR4nO2df3Qcdbn/389uNsm25Zs0Tf3RpLVFOEUphUpEvORwLxQpIJZYJUJVLiK394ocBL3F8tUDheP3Wqny6yu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vlb93CekIgiBEBDH4giAIEaGeDf6qai+gish7jy5Rfv/y3iukbmP4giAIQmnUs4cvCIIglIAYfEEQhIhQ1wafiFYS0RtEtImIHiGi1mqvKSiI6Hwi2kxEOSKKRKkaEZ1FRFuI6C0iWlbt9QQFEd1DRH8jolervZagIaLpRPQ8Eb2W/3//RrXXFCRE1ExEfyCijfn3f30lx6trgw/gaQBzmHkugP8GcE2V1xMkrwJYBOCFai8kCIgoDuB2AGcD+CiAC4noo9VdVWDcC+Csai+iSowC+BYzfxTAyQC+HqG/OwAcBnA6Mx8P4AQAZxHRyeUerK4NPjM/xcyj+YcvAYjMfDhmfp2Zt1R7HQFyEoC3mHkrM48AeBDAeVVeUyAw8wsA9lR7HdWAmf/CzC/nf34PwOsAOqq7quBgjf35h4n8V9mVNnVt8E1cAuDX1V6E4BsdALYbHg8hQh98ASCimQDmAfh9lZcSKEQUJ6INAP4G4GlmLvv91/zEKyJ6BsAHLJ76DjM/mt/nO9Bu/e4Pcm1+4+a9C0IUIKJJAB4CcCUzv1vt9QQJM2cBnJDPUT5CRHOYuax8Ts0bfGY+w+55IroYwLkA5nPImgqc3nvESAGYbnjcmd8mhBwiSkAz9vcz88PVXk+1YOZhInoeWj6nLINf1yEdIjoLwNUAFjLzwWqvR/CVPwI4mohmEVEjgAsADFR5TYLPEBEBuBvA68x8U7XXEzRENFWvPiSiJIBPAXij3OPVtcEH8GMARwB4mog2ENGd1V5QUBDRZ4loCMAnATxBRGuqvSY/ySfnLwewBlriro+ZN1d3VcFARA8A+B2A2UQ0RERfrfaaAuQUAF8GcHr+M76BiM6p9qIC5IMAnieiTdCcnqeZ+fFyDybSCoIgCBGh3j18QRAEwSVi8AVBECKCGHxBEISIIAZfEAQhIojBFwRBiAhi8AVBECKCGHxBEISI8P8BI9EsSrGD0r8AAAAASUVORK5CYII=\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#x是特征，y是标签\n",
    "x, y = datasets.make_moons(n_samples=50000, noise=0.3, random_state=42)\n",
    "print(x.shape)\n",
    "print(y.shape)\n",
    "print(np.unique(y))\n",
    "plt.scatter(x[y == 0, 0], x[y == 0, 1])  #拿到特征中标签为0的第0列，拿到标签为0的第一列\n",
    "plt.scatter(x[y == 1, 0], x[y == 1, 1]) #拿到特征中标签为1的第0列，拿到标签为1的第一列\n",
    "plt.legend(['0', '1'])\n",
    "plt.show()  #图形的点颜色是自动的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "array([ 0.11096372,  0.61562814,  0.46175947, ...,  0.27571831,\n        0.90929791, -0.97512015])"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#选样本中标签为0的那些样本的，第零列特征\n",
    "x[y == 0,0]"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "array([[ 0.71820567, -0.21809028],\n       [ 0.11096372,  1.10964541],\n       [ 0.61562814, -0.06539887],\n       ...,\n       [ 1.58004352, -0.3637176 ],\n       [ 0.90929791, -0.09962261],\n       [-0.97512015,  0.87195198]])"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "array([0, 1], dtype=int64)"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.unique(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:45:31.312853300Z",
     "start_time": "2024-04-19T08:45:31.166892800Z"
    }
   },
   "outputs": [],
   "source": [
    "#默认分割比例是75%和25%\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=42)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:45:40.743405600Z",
     "start_time": "2024-04-19T08:45:40.579517600Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.85344"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.linear_model import LogisticRegression\n",
    "#逻辑回归是搞分类的\n",
    "log_clf = LogisticRegression()\n",
    "log_clf.fit(x_train, y_train)\n",
    "log_clf.score(x_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:46:11.669886300Z",
     "start_time": "2024-04-19T08:45:44.719434900Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.91216"
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.svm import SVC\n",
    "\n",
    "svm_clf = SVC()\n",
    "svm_clf.fit(x_train, y_train)\n",
    "svm_clf.score(x_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:46:18.642417900Z",
     "start_time": "2024-04-19T08:46:18.363803400Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.87568"
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "\n",
    "dt_clf = DecisionTreeClassifier()\n",
    "dt_clf.fit(x_train, y_train)\n",
    "dt_clf.score(x_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 1 手动实现投票分类器"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:48:03.195482800Z",
     "start_time": "2024-04-19T08:47:52.082496300Z"
    }
   },
   "outputs": [],
   "source": [
    "#训练好模型，测试集做预测\n",
    "y_predict1 = log_clf.predict(x_test)\n",
    "y_predict2 = svm_clf.predict(x_test)\n",
    "y_predict3 = dt_clf.predict(x_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:48:05.310822400Z",
     "start_time": "2024-04-19T08:48:05.286839Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "array([1, 1, 1, 0, 0, 0, 0, 0, 0, 1])"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#bagging，纯手动bagging\n",
    "y_predict = np.array((y_predict1 + y_predict2 + y_predict3) >= 2, dtype='int')\n",
    "y_predict[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:48:11.732548200Z",
     "start_time": "2024-04-19T08:48:11.708564Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "array([1, 1, 1, 0, 0, 0, 0, 1, 0, 1], dtype=int64)"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_test[:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:48:14.536918Z",
     "start_time": "2024-04-19T08:48:14.523921600Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.90432"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "#accuracy_score计算准确率的\n",
    "accuracy_score(y_test, y_predict)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 2 集成学习VotingClassifier(并行)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:50:51.724817100Z",
     "start_time": "2024-04-19T08:50:51.663825300Z"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.ensemble import VotingClassifier\n",
    "\n",
    "#hard模式就是少数服从多数\n",
    "voting_clf = VotingClassifier(estimators=[\n",
    "    ('log_clf', LogisticRegression()),\n",
    "    ('svm_clf', SVC()),\n",
    "    ('dt_clf', DecisionTreeClassifier())], voting='hard')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:51:24.922276600Z",
     "start_time": "2024-04-19T08:50:56.134327200Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.90472"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "voting_clf.fit(x_train, y_train)\n",
    "voting_clf.score(x_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "更合理的投票，应该有权值\n",
    "唱歌比赛的投票?(评委的投票权重与观众不一样)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.90352"
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# hard和soft区别请看课件解释\n",
    "voting_clf2 = VotingClassifier(estimators=[\n",
    "    ('log_clf', LogisticRegression()),\n",
    "    ('svm_clf', SVC(probability=True)),  #支持向量机中需要加入probability\n",
    "    ('dt_clf', DecisionTreeClassifier())], voting='soft')\n",
    "voting_clf2.fit(x_train, y_train)\n",
    "voting_clf2.score(x_test, y_test)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "使用bagging"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "37500.0"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "50000*0.75"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "data": {
      "text/plain": "0.91248"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier  #用决策树集成上千模型\n",
    "from sklearn.ensemble import BaggingClassifier\n",
    "\n",
    "#估计器数目是5000呢？bootstrap是有放回抽样,max_samples不可以超过训练集的数目37500\n",
    "bagging_clf = BaggingClassifier(DecisionTreeClassifier(), n_estimators=300,\n",
    "                                max_samples=3000, bootstrap=True)\n",
    "bagging_clf.fit(x_train, y_train)\n",
    "bagging_clf.score(x_test, y_test)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    },
    "ExecuteTime": {
     "end_time": "2024-04-19T08:54:30.817171300Z",
     "start_time": "2024-04-19T08:54:25.790579100Z"
    }
   }
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 3 oob设计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.91136"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bagging_clf2 = BaggingClassifier(DecisionTreeClassifier(), n_estimators=500, max_samples=100,\n",
    "                                 bootstrap=True,\n",
    "                                 oob_score=True)\n",
    "bagging_clf2.fit(x_train, y_train)\n",
    "bagging_clf2.oob_score_  #拿没有取到的数据集作为验证集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "data": {
      "text/plain": "0.90904"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bagging_clf2.score(x_test, y_test)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "### njobs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier  #用决策树集成上千模型\n",
    "from sklearn.ensemble import BaggingClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: total: 4.42 s\n",
      "Wall time: 4.82 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "0.91272"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "bagging_clf = BaggingClassifier(DecisionTreeClassifier(),\n",
    "                                n_estimators=500, max_samples=2000,\n",
    "                                bootstrap=True)\n",
    "bagging_clf.fit(x_train, y_train)\n",
    "bagging_clf.score(x_test, y_test)\n",
    "#cpu time是实际cpu运行算法时间，wall time是墙上真实时间，就是real time（包含了进程启动时间，I/O等待时间等）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: total: 453 ms\n",
      "Wall time: 5.51 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "0.91208"
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "#多核使用的时间更小, %%time要顶格来写\n",
    "bagging_clf = BaggingClassifier(DecisionTreeClassifier(),\n",
    "                                n_estimators=500, max_samples=2000,\n",
    "                                bootstrap=True, n_jobs=-1)\n",
    "bagging_clf.fit(x_train, y_train)\n",
    "bagging_clf.score(x_test, y_test)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 4 bootstrap_features  对特征进行采样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.8827"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#因为我们就两个特征，所以max_features设置为1,得到的分值较低是因为我们特征较少，采用随机特征不合适\n",
    "#这个是只对特征进行采样\n",
    "random_subspaces_clf = BaggingClassifier(DecisionTreeClassifier(),\n",
    "                                         n_estimators=500, max_samples=500, oob_score=True,\n",
    "                                         bootstrap=True, n_jobs=-1,\n",
    "                                         max_features=1, bootstrap_features=True)\n",
    "random_subspaces_clf.fit(x, y)\n",
    "random_subspaces_clf.oob_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "max_samples must be in (0, n_samples]",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mValueError\u001B[0m                                Traceback (most recent call last)",
      "Input \u001B[1;32mIn [26]\u001B[0m, in \u001B[0;36m<cell line: 6>\u001B[1;34m()\u001B[0m\n\u001B[0;32m      1\u001B[0m \u001B[38;5;66;03m# 这里是为了验证总的抽样的样本数不能大于训练集的数目\u001B[39;00m\n\u001B[0;32m      2\u001B[0m random_patches_clf \u001B[38;5;241m=\u001B[39m BaggingClassifier(DecisionTreeClassifier(),\n\u001B[0;32m      3\u001B[0m                                        n_estimators\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m500\u001B[39m, max_samples\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m50001\u001B[39m, oob_score\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m      4\u001B[0m                                        bootstrap\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m, n_jobs\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m-\u001B[39m\u001B[38;5;241m1\u001B[39m,\n\u001B[0;32m      5\u001B[0m                                        max_features\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m1\u001B[39m, bootstrap_features\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[1;32m----> 6\u001B[0m \u001B[43mrandom_patches_clf\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mfit\u001B[49m\u001B[43m(\u001B[49m\u001B[43mx\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43my\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m      7\u001B[0m random_patches_clf\u001B[38;5;241m.\u001B[39moob_score_\n",
      "File \u001B[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\sklearn\\ensemble\\_bagging.py:269\u001B[0m, in \u001B[0;36mBaseBagging.fit\u001B[1;34m(self, X, y, sample_weight)\u001B[0m\n\u001B[0;32m    260\u001B[0m \u001B[38;5;66;03m# Convert data (X is required to be 2d and indexable)\u001B[39;00m\n\u001B[0;32m    261\u001B[0m X, y \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_validate_data(\n\u001B[0;32m    262\u001B[0m     X,\n\u001B[0;32m    263\u001B[0m     y,\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    267\u001B[0m     multi_output\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m    268\u001B[0m )\n\u001B[1;32m--> 269\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_fit\u001B[49m\u001B[43m(\u001B[49m\u001B[43mX\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43my\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mmax_samples\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43msample_weight\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43msample_weight\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32m~\\AppData\\Roaming\\Python\\Python39\\site-packages\\sklearn\\ensemble\\_bagging.py:328\u001B[0m, in \u001B[0;36mBaseBagging._fit\u001B[1;34m(self, X, y, max_samples, max_depth, sample_weight)\u001B[0m\n\u001B[0;32m    325\u001B[0m     max_samples \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mint\u001B[39m(max_samples \u001B[38;5;241m*\u001B[39m X\u001B[38;5;241m.\u001B[39mshape[\u001B[38;5;241m0\u001B[39m])\n\u001B[0;32m    327\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m (\u001B[38;5;241m0\u001B[39m \u001B[38;5;241m<\u001B[39m max_samples \u001B[38;5;241m<\u001B[39m\u001B[38;5;241m=\u001B[39m X\u001B[38;5;241m.\u001B[39mshape[\u001B[38;5;241m0\u001B[39m]):\n\u001B[1;32m--> 328\u001B[0m     \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmax_samples must be in (0, n_samples]\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[0;32m    330\u001B[0m \u001B[38;5;66;03m# Store validated integer row sampling value\u001B[39;00m\n\u001B[0;32m    331\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_max_samples \u001B[38;5;241m=\u001B[39m max_samples\n",
      "\u001B[1;31mValueError\u001B[0m: max_samples must be in (0, n_samples]"
     ]
    }
   ],
   "source": [
    "# 这里是为了验证总的抽样的样本数不能大于训练集的数目\n",
    "random_patches_clf = BaggingClassifier(DecisionTreeClassifier(),\n",
    "                                       n_estimators=500, max_samples=50001, oob_score=True,\n",
    "                                       bootstrap=True, n_jobs=-1,\n",
    "                                       max_features=1, bootstrap_features=True)\n",
    "random_patches_clf.fit(x, y)\n",
    "random_patches_clf.oob_score_\n",
    "#这个代码有另外一个名字就是随机森林"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.ensemble import RandomForestClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: total: 56.9 s\n",
      "Wall time: 14.1 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "0.90322"
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "rc_clf = RandomForestClassifier(n_estimators=500, random_state=666,\n",
    "                                oob_score=True, n_jobs=-1)\n",
    "rc_clf.fit(x, y)\n",
    "rc_clf.oob_score_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: total: 8.03 s\n",
      "Wall time: 1.53 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "0.90296"
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "rc_clf = RandomForestClassifier(max_samples=37500, n_jobs=-1)\n",
    "rc_clf.fit(x_train, y_train)\n",
    "rc_clf.score(x_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: total: 32.5 s\n",
      "Wall time: 8.71 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "0.90962"
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "#max_leaf_nodes 最大的叶子结点数\n",
    "rc_clf2 = RandomForestClassifier(n_estimators=500, max_leaf_nodes=16,\n",
    "                                 random_state=666,\n",
    "                                 oob_score=True, n_jobs=-1)\n",
    "rc_clf2.fit(x, y)\n",
    "rc_clf2.oob_score_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 5 Extra-Trees\n",
    "ExtraTreesClassifier 是一种机器学习算法，属于基于决策树的集成方法家族。\n",
    "它随机选择特征子集和数据样本来构建多个决策树，并将它们的预测聚合起来做出最终预测。\n",
    "它可用于分类任务，并以处理嘈杂和高维数据的能力而闻名。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.90694"
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.ensemble import ExtraTreesClassifier\n",
    "\n",
    "et_clf = ExtraTreesClassifier(n_estimators=500, oob_score=True,\n",
    "                              bootstrap=True, n_jobs=-1)\n",
    "et_clf.fit(x, y)\n",
    "et_clf.oob_score_"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "Boosting"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "# 5 串行（包含adaboost和GBDT）"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.ensemble import AdaBoostClassifier\n",
    "from sklearn.tree import DecisionTreeClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: total: 172 ms\n",
      "Wall time: 142 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "0.87592"
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "ada_clf = AdaBoostClassifier(DecisionTreeClassifier(),\n",
    "                             n_estimators=500)\n",
    "ada_clf.fit(x_train, y_train)\n",
    "ada_clf.score(x_test, y_test)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": "0.91184"
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#它默认用的也是决策树，增加了基分类器的数目后，准确率提升\n",
    "from sklearn.ensemble import GradientBoostingClassifier\n",
    "\n",
    "gb_clf = GradientBoostingClassifier(max_depth=3, n_estimators=500)\n",
    "gb_clf.fit(x_train, y_train)\n",
    "gb_clf.score(x_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.1972245773362196\n"
     ]
    },
    {
     "data": {
      "text/plain": "0.0"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "print(np.log(9))  #当错误率是0.1时权重是2.19\n",
    "np.log((1-0.5)/0.5)  #当错误率是0.5时，权重是0"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
